Skip to content

mbe: Rework diagnostics for metavariable expressions #142950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Jun 24, 2025

Make the diagnostics for metavariable expressions more user-friendly. This mostly addresses syntactic errors; I will be following up with improvements to concat(..).

r? @petrochenkov

@rustbot rustbot added A-tidy Area: The tidy tool S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 24, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 24, 2025

There are changes to the tidy tool.

cc @jieyouxu

@tgross35 tgross35 added the F-macro_metavar_expr `#![feature(macro_metavar_expr)]` label Jun 24, 2025
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 24, 2025
@tgross35 tgross35 changed the title mbe: Rework diagnostics for metavariable expressions. mbe: Rework diagnostics for metavariable expressions Jun 30, 2025
@tgross35
Copy link
Contributor Author

I split the nonfunctional changes here to a new PR, #143245. I think this should make it a bit more straightforward to do the other changes here.

@petrochenkov
Copy link
Contributor

Blocked on #143245.
@rustbot blocked

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 30, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 1, 2025
…ation, r=petrochenkov

mbe: Add tests and restructure metavariable expressions

Add tests that show better diagnostics, and factor `concat` handling to a separate function. Each commit message has further details.

This performs the nonfunctional perparation for further changes such as rust-lang#142950 and rust-lang#142975 .
@tgross35
Copy link
Contributor Author

tgross35 commented Jul 1, 2025

@rustbot author
after that merges I’m going to do some cleanup of this and the remaining draft PR

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Jul 1, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 1, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

rust-timer added a commit that referenced this pull request Jul 1, 2025
Rollup merge of #143245 - tgross35:metavariable-expr-organization, r=petrochenkov

mbe: Add tests and restructure metavariable expressions

Add tests that show better diagnostics, and factor `concat` handling to a separate function. Each commit message has further details.

This performs the nonfunctional perparation for further changes such as #142950 and #142975 .
@bors

This comment was marked as resolved.

@tgross35 tgross35 force-pushed the metavariable-expr-rework branch 2 times, most recently from 51693ef to 1146773 Compare July 4, 2025 06:37
@rust-log-analyzer

This comment has been minimized.

@tgross35 tgross35 force-pushed the metavariable-expr-rework branch 3 times, most recently from 13a7e49 to 7e5760b Compare July 4, 2025 08:55
@tgross35 tgross35 force-pushed the metavariable-expr-rework branch from 7e5760b to 5366b37 Compare July 4, 2025 08:58
@tgross35
Copy link
Contributor Author

tgross35 commented Jul 4, 2025

I rebased on top of #143245 and dropped the more confusing identifier changes, which makes more sense to bring back as part of #142975.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 4, 2025
@tgross35 tgross35 force-pushed the metavariable-expr-rework branch from 5366b37 to b276ff8 Compare July 4, 2025 09:28
}

/// Map of `(name, max_arg_count, variable_count)`.
const EXPR_NAME_ARG_MAP: &[(&str, ArgSpec)] = &[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only used once, probably better to turn it into a match on strings.

];

/// List of the above for diagnostics
const VALID_METAVAR_EXPR_NAMES: &str = "`count`, `ignore`, `index`, `len`, and `concat`";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also only used once.

@petrochenkov
Copy link
Contributor

r=me with the comments addressed.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 9, 2025
tgross35 added 2 commits July 9, 2025 21:08
Give a more user-friendly diagnostic about the following:

* Trailing tokens within braces, e.g. `${foo() extra}`
* Missing parentheses, e.g. `${foo}`
* Incorrect number of arguments, with a hint about correct usage.
Change to a structural diagnostic, update the valid list, and move the
valid list to a note.
@tgross35 tgross35 force-pushed the metavariable-expr-rework branch from b276ff8 to dff37db Compare July 10, 2025 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tidy Area: The tidy tool F-macro_metavar_expr `#![feature(macro_metavar_expr)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants